---
title: "RabbitMQ sink"
sidebarTitle: "RabbitMQ sink"
description: "Reference for configuring and using the RabbitMQ sink with Sequin."
---

The RabbitMQ sink publishes messages to RabbitMQ exchanges.

<Tip>
  This is the reference for the RabbitMQ sink. See the [quickstart](/quickstart/rabbitmq) for a step-by-step walkthrough or the [how-to guide](/how-to/stream-postgres-to-rabbitmq) for an explanation of how to use the RabbitMQ sink.
</Tip>

## Configuration

- **Host**

    The hostname of your RabbitMQ server (e.g., `localhost`).

- **Port**

    The port number for your RabbitMQ server (default: `5672`).

- **Exchange**

    The name of the exchange to publish messages to. Maximum length is 255 characters.

- **Virtual Host**

    The RabbitMQ virtual host (default: "/").

- **Username**

    Your RabbitMQ username (default: "guest").

- **Password**

    Your RabbitMQ password (default: "guest").

- **TLS**

    Enable if your RabbitMQ server requires TLS/SSL connection.

## Message format

Sequin sends messages to RabbitMQ as JSON. You can find the shape of the messages in the [messages reference](/reference/messages).

## Routing keys

Messages are published with routing keys using the following pattern:

```
sequin.<database_name>.<schema_name>.<table_name>.<action>
```

For example, if you're streaming changes from a table called `products` in the `public` schema of a database called `shop_prod`, you would see routing keys like:

- `sequin.shop_prod.public.products.insert`
- `sequin.shop_prod.public.products.update`
- `sequin.shop_prod.public.products.delete`

## Message properties

Each message includes the following AMQP properties:

- `message_id`: A unique Sequin identifier for the message
- `content_type`: Set to "application/json"

## Retry behavior

If Sequin is unable to deliver a message to RabbitMQ, it will retry the message indefinitely. Sequin will exponentially back off the retry interval, with a maximum backoff of roughly 3 minutes.

## Message ordering

RabbitMQ preserves message order within a queue. Messages are published to RabbitMQ exchanges in the same order that they are received from your source table.

<Note>
  If you have multiple consumers on a queue or use different queues bound to the same exchange, you may not receive messages in the same order that they were published.
</Note>

## Exchange and queue setup

Before using the RabbitMQ sink, you need to:

1. Create an exchange
2. Create one or more queues
3. Bind the queues to the exchange with appropriate routing key patterns

You can do this through the RabbitMQ management UI or using the `rabbitmqadmin` CLI tool.

For example, to receive all changes to a table:
```bash
# Create a topic exchange
rabbitmqadmin declare exchange name=sequin type=topic

# Create a queue
rabbitmqadmin declare queue name=my-queue

# Bind queue to exchange with wildcard routing key
rabbitmqadmin declare binding \
  source=sequin \
  destination=my-queue \
  routing_key="sequin.changes.mydb.public.mytable.*"
```

## Routing

The RabbitMQ sink supports dynamic routing of the `exchange`, `routing_key`, and message `headers` with [routing functions](/reference/routing).

Example routing function:

```elixir
def route(action, record, changes, metadata) do
  %{
    exchange: "sequin_" <> metadata.table_schema,
    routing_key: "#{metadata.database_name}.#{metadata.table_schema}.#{metadata.table_name}.#{action}",
    headers: %{"Idempotency-Key" => metadata.idempotency_key}
  }
end
```

When not using a routing function, messages will be published to the statically configured exchange with any headers specified in the sink configuration.

## Debugging

You can view the status of your RabbitMQ sink in the Sequin web console.

On the "Messages" tab, you can see which messages are in-flight to RabbitMQ, which messages Sequin is unable to deliver, and recently delivered messages.

Messages that Sequin is unable to deliver will have a "Deliver count" greater than `1`. You can click on a message to see more details, including the last error response received from RabbitMQ.
